package com.ruoyi.web.controller.drinkwater;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.base.domain.BusWaterSegment;
import com.ruoyi.base.service.IBusWaterSegmentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.drinkwater.domain.ManualParamVo;
import com.ruoyi.drinkwater.service.BaseDrinkSegmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/drink/segment")
public class BaseDrinkSegmentController extends BaseController {

    @Autowired
    private BaseDrinkSegmentService baseDrinkSegmentService;

    /**
     * 水源地河流断面树
     */
    @GetMapping("/drinkSegmentTree")
    public AjaxResult drinkSegmentTree(ManualParamVo vo) {
        Map map = new HashMap();//存放传入参数
        map.put("segmentName", vo.getSegmentName());
        map.put("segmentType", vo.getSegmentType());
        //segmentCategory
        if(vo.getDataType()!=null&&vo.getDataType().equals("0")){
            List<String> segmentCategory=new ArrayList<>();
            segmentCategory.add("1");
            segmentCategory.add("2");
            map.put("segmentCategory", segmentCategory);
        }
        if(vo.getDataType()!=null&&vo.getDataType().equals("1")){
            List<String> segmentCategory=new ArrayList<>();
            segmentCategory.add("3");
            map.put("segmentCategory", segmentCategory);
        }
        if(vo.getDataType()!=null&&vo.getDataType().equals("2")){
            List<String> segmentCategory=new ArrayList<>();
            segmentCategory.add("2");
            map.put("segmentCategory", segmentCategory);
        }
        //查询监测数据
        List list = baseDrinkSegmentService.selectDrinksourceTypesegment(map);

        return AjaxResult.success(list);
    }

    @GetMapping("/maunalDataManagementsyd")
    public Map maunalDataManagementsyd(String segmentId, String dataTime,  String prop,Integer pageNum, Integer pageSize) {
        Map map = new HashMap(); //存放传入参数

        if (prop != null && !"".equals(prop)) {
            map.put("prop", prop);
        } else {
            map.put("prop", "CBF1");
        }
        List<String> segmentids = null;
        if (segmentId != null && !"".equals(segmentId)) {
            String[] arr = segmentId.split(",");
            segmentids = Arrays.asList(arr);
            map.put("segmentids", segmentids);

        }
        map.put("dataTime", dataTime);
        //查询处理后的结果数据值
        List<Map<Object, Object>> manualWqDataBasicsmonitordata = baseDrinkSegmentService.maunalDataManagement(map);
        //没有办法调用工具和sql进行分页调用Java 对应方法进行分页查询
        List<Map> collect = manualWqDataBasicsmonitordata.stream().skip((pageNum - 1) * pageSize)
                .limit(pageSize)
                .collect(Collectors.toList());
        //获取总条数
        int size = manualWqDataBasicsmonitordata.size();
        //返回数据结果集
        Map maplist = new HashMap();
        maplist.put("rows", collect);
        maplist.put("code", 200);
        maplist.put("msg", "查询成功");
        maplist.put("total", size);
        return maplist;
    }

    @RequestMapping("/deleteMaunalSegmentsyd")
    public Map deleteMaunalSegmentsyd(@RequestBody  ManualParamVo vo) {
       List<String> segmentIdList=Arrays.asList(vo.getSegmentId().split(","));
        List<String> reportIdList=Arrays.asList(vo.getReportId().split(","));
        List<ManualParamVo> dvo=new ArrayList<>();
        int i=0;
        for(String segmentId:segmentIdList){
            ManualParamVo paramVo=new ManualParamVo();
            paramVo.setSegmentId(segmentId);
            paramVo.setReportId(reportIdList.get(i));
            paramVo.setSampleDate(vo.getSampleDate());
            paramVo.setBussinessCategoryCode(vo.getBussinessCategoryCode());
            dvo.add(paramVo);
            i++;
        }
        Integer integer = baseDrinkSegmentService.deleteMaunalSegmentsyd(dvo);
        //返回数据结果集
        Map maplist = new HashMap();
        maplist.put("data", integer);
        maplist.put("code", 200);
        maplist.put("msg", "删除成功");
        return maplist;
    }


}
